#ifndef B2_WORLD_CLONE_STATE_H
#define B2_WORLD_CLONE_STATE_H

#include <gvl/hash_set/hash_set.hpp>

struct PtrIndex
{
	PtrIndex()
	: first(0)
	{
	}

	PtrIndex(void const* firstInit, void* secondInit)
	: first(firstInit)
	, second(secondInit)
	{
	}

	operator bool() const
	{ return first != 0; }

	gvl::hash_t hash(unsigned p) const
	{ return gvl::hash(first, p); }

	bool operator==(PtrIndex const& other) const
	{ return first == other.first; }

	bool operator==(void const* k) const
	{ return first == k; }

	void const* first;
	void* second;
};

class b2World;

struct b2WorldCloneState
{
	b2WorldCloneState(b2World* world)
	: world(world)
	{
	}

	void addPtrMap(void const* from, void* to)
	{
		ptrMap.insert(PtrIndex(from, to));
	}

	template<typename T>
	T* mapPtr(T const* from)
	{
		void const* fromv = from;
		return static_cast<T*>(ptrMap.get(fromv)->second);
	}

	b2World* world;
	gvl::hash_set_unboxed<PtrIndex> ptrMap;
};

#endif // B2_WORLD_CLONE_STATE_H

